<template>
  <view 
    class="poker-card" 
    :class="[
      selected ? 'selected' : '', 
      cardSize,
      disabled ? 'disabled' : ''
    ]"
    :style="{ transform: `translateY(${selected ? -20 : 0}rpx)` }"
    @tap="handleClick"
  >
    <!-- 牌背面 -->
    <view v-if="showBack" class="card-back">
      <view class="back-pattern"></view>
    </view>
    
    <!-- 牌正面 -->
    <view v-else class="card-front" :class="[
      card.suit === '♥' || card.suit === '♦' ? 'red-suit' : 'black-suit'
    ]">
      <!-- 左上角 -->
      <view class="card-corner top-left">
        <text class="rank-text">{{ card.rank }}</text>
        <text class="suit-text">{{ card.suit }}</text>
      </view>
      
      <!-- 中间 -->
      <view class="card-center">
        <text class="suit-large">{{ card.suit }}</text>
      </view>
      
      <!-- 右下角 -->
      <view class="card-corner bottom-right">
        <text class="rank-text">{{ card.rank }}</text>
        <text class="suit-text">{{ card.suit }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'PokerCard',
  props: {
    // 牌数据 { suit, rank, value, id }
    card: {
      type: Object,
      default: () => ({})
    },
    // 是否显示牌背面
    showBack: {
      type: Boolean,
      default: false
    },
    // 是否选中
    selected: {
      type: Boolean,
      default: false
    },
    // 是否禁用点击
    disabled: {
      type: Boolean,
      default: false
    },
    // 卡牌大小 small/normal/large
    cardSize: {
      type: String,
      default: 'normal'
    }
  },
  
  methods: {
    handleClick() {
      if (!this.disabled && !this.showBack) {
        this.$emit('click', this.card)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.poker-card {
  position: relative;
  border-radius: 8rpx;
  box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  
  &.small {
    width: 60rpx;
    height: 84rpx;
  }
  
  &.normal {
    width: 100rpx;
    height: 140rpx;
  }
  
  &.large {
    width: 140rpx;
    height: 196rpx;
  }
  
  &.selected {
    box-shadow: 0 8rpx 16rpx rgba(255, 215, 0, 0.5);
    border: 3rpx solid #ffd700;
  }
  
  &.disabled {
    opacity: 0.5;
  }
}

.card-back {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  
  .back-pattern {
    width: 80%;
    height: 80%;
    border: 3rpx solid rgba(255, 255, 255, 0.3);
    border-radius: 4rpx;
    background: repeating-linear-gradient(
      45deg,
      transparent,
      transparent 10rpx,
      rgba(255, 255, 255, 0.1) 10rpx,
      rgba(255, 255, 255, 0.1) 20rpx
    );
  }
}

.card-front {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 8rpx;
  border: 2rpx solid #e0e0e0;
  position: relative;
  
  &.red-suit {
    .rank-text, .suit-text, .suit-large {
      color: #f44336;
    }
  }
  
  &.black-suit {
    .rank-text, .suit-text, .suit-large {
      color: #333;
    }
  }
}

.card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  
  &.top-left {
    top: 8rpx;
    left: 8rpx;
  }
  
  &.bottom-right {
    bottom: 8rpx;
    right: 8rpx;
    transform: rotate(180deg);
  }
  
  .rank-text {
    font-size: 24rpx;
    font-weight: bold;
    line-height: 1;
  }
  
  .suit-text {
    font-size: 20rpx;
    line-height: 1;
    margin-top: 2rpx;
  }
}

.card-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  
  .suit-large {
    font-size: 60rpx;
    line-height: 1;
  }
}

// 大尺寸卡牌样式调整
.poker-card.large {
  .card-corner {
    &.top-left {
      top: 12rpx;
      left: 12rpx;
    }
    
    &.bottom-right {
      bottom: 12rpx;
      right: 12rpx;
    }
    
    .rank-text {
      font-size: 32rpx;
    }
    
    .suit-text {
      font-size: 28rpx;
    }
  }
  
  .card-center .suit-large {
    font-size: 80rpx;
  }
}

// 小尺寸卡牌样式调整
.poker-card.small {
  .card-corner {
    &.top-left {
      top: 4rpx;
      left: 4rpx;
    }
    
    &.bottom-right {
      bottom: 4rpx;
      right: 4rpx;
    }
    
    .rank-text {
      font-size: 16rpx;
    }
    
    .suit-text {
      font-size: 14rpx;
    }
  }
  
  .card-center .suit-large {
    font-size: 36rpx;
  }
}
</style>
